import React,{Component} from 'react';
import './index.css'

export default class Footer extends Component{
    
    //全选的回调
    handleCheckAll = (event)=>{
        this.props.checkAllTodo(event.target.checked)
    }

    //清除所有已完成的待办
    handleClearAllDone=()=>{
        this.props.clearAllDone();
    }

    render(){
        //获取参数
        const{todos} = this.props;
        //全部的待办
        const total = todos.length;
        //已完成的待办
        const doneCount = todos.reduce((pre,todo)=>pre + (todo.done ? 1 : 0),0)
        return(
            <div className="todo-footer">
                <label>
                    <input type="checkbox" onChange={this.handleCheckAll} checked={doneCount === total && total !== 0 ? true : false}/>
                </label>
                <span>
                    <span>已完成{doneCount}</span> / 全部{total}
                </span>
                <button onClick={this.handleClearAllDone} className="btn btn-danger">清除已完成任务</button>
            </div>
        )
    }
}